package org.dromara.system.service.impl;

import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.utils.BeanCopyUtils;
import org.dromara.system.mapper.SysClientMapper;
import org.dromara.system.pojo.bo.SysClientBO;
import org.dromara.system.pojo.entity.SysClientDO;
import org.dromara.system.pojo.qo.SysClientQO;
import org.dromara.system.pojo.vo.SysClientVO;
import org.dromara.system.service.SysClientService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 系统授权表 服务层实现。
 *
 * @author mkj
 * @since 2024-07-21
 */
@RequiredArgsConstructor
@Service
public class SysClientServiceImpl implements SysClientService {

    private final SysClientMapper sysClientMapper;

    @Override
    public boolean add(SysClientBO sysClientBO) {
        SysClientDO sysClientDO = BeanCopyUtils.copy(sysClientBO, SysClientDO.class);
        return sysClientMapper.insert(sysClientDO) > 0;
    }

    @Override
    public boolean remove(Long id) {
        return sysClientMapper.deleteById(id) > 0;
    }

    @Override
    public boolean update(SysClientBO sysClientBO) {
        SysClientDO sysClientDO = BeanCopyUtils.copy(sysClientBO, SysClientDO.class);
        return sysClientMapper.update(sysClientDO) > 0;
    }

    @Override
    public List<SysClientVO> list(SysClientQO sysClientQO) {
        SysClientDO sysClientDO = BeanCopyUtils.copy(sysClientQO, SysClientDO.class);
        QueryWrapper queryWrapper = QueryWrapper.create(sysClientDO);
        return sysClientMapper.selectListByQueryAs(queryWrapper, SysClientVO.class);
    }

    @Override
    public SysClientVO getInfo(Long id) {
        SysClientDO sysClientDO = sysClientMapper.selectOneById(id);
        if (sysClientDO == null) {
            return null;
        }
        return BeanCopyUtils.copy(sysClientDO, SysClientVO.class);
    }

    @Override
    public Page<SysClientVO> page(SysClientQO page) {
        return sysClientMapper.paginateAs(page.getPageNumber(), page.getPageSize(), QueryWrapper.create(page), SysClientVO.class);
    }

}

